#include <Windows.h>

#include <atlbase.h>
#include <atlcom.h>
#include <atlcoll.h>
#include <atlwin.h>

#include <shlobj.h>
#include <shobjidl.h>
#include <shellapi.h>
#include <shlwapi.h>
#include <shlguid.h>
#include <ntquery.h>
#include <thumbcache.h>

static CLSID MODULE_GUID = { 0x1007d097, 0xddd1, 0x47df, { 0xb4, 0x4, 0x36, 0x14, 0x59, 0xd9, 0xb6, 0x74 } };

class CAtlDllModule : public CAtlDllModuleT<CAtlDllModule>
{ };

CAtlDllModule _AtlModule;

BOOL WINAPI DllMain(
  _In_  HINSTANCE hinstDLL,
  _In_  DWORD fdwReason,
  _In_  LPVOID lpvReserved
)
{
	switch (fdwReason)
	{
	case DLL_PROCESS_ATTACH:
		//MessageBox(NULL, "DLL_PROCESS_ATTACH", "DLL_PROCESS_ATTACH", MB_OK);
		break;
	case DLL_PROCESS_DETACH:
		//MessageBox(NULL, "DLL_PROCESS_DETACH", "DLL_PROCESS_DETACH", MB_OK);
		break;
	case DLL_THREAD_ATTACH:
		//MessageBox(NULL, "DLL_THREAD_ATTACH", "DLL_THREAD_ATTACH", MB_OK);
		break;
	case DLL_THREAD_DETACH:
		//MessageBox(NULL, "DLL_THREAD_DETACH", "DLL_THREAD_DETACH", MB_OK);
		break;
	}

	return TRUE;
}

// REGSVR32 support

STDAPI DllCanUnloadNow()
{
   return _AtlModule.DllCanUnloadNow();
}

STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
   return _AtlModule.DllGetClassObject(rclsid, riid, ppv);
}

STDAPI DllRegisterServer()
{
   ATLTRACE(L"DllRegisterServer\n");
   _AtlModule.DllRegisterServer(FALSE);
   //HR( _ShellModule.DllInstall() );
   return S_OK;
}

STDAPI DllUnregisterServer()
{
   ATLTRACE(L"DllUnregisterServer\n");
   //_ShellModule.DllUninstall();
   _AtlModule.DllUnregisterServer(FALSE);
   return S_OK;
}


//update registry test
CLSID CLASS_GUID = { 0x572b2291, 0x5b68, 0x4c74, { 0x82, 0x3, 0xe9, 0xb9, 0x4, 0x50, 0x8c, 0x8d } };

class RegisterTest:
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<RegisterTest, &CLASS_GUID>

{
public:
   static HRESULT WINAPI UpdateRegistry(BOOL bRegister) throw();

   BEGIN_COM_MAP(RegisterTest)
      //COM_INTERFACE_ENTRY(IShellFolder)
      //COM_INTERFACE_ENTRY(IShellFolder2)
      //COM_INTERFACE_ENTRY(IPersistIDList)
      //COM_INTERFACE_ENTRY(IShellIcon)
      //COM_INTERFACE_ENTRY(IShellIconOverlay)
      //COM_INTERFACE_ENTRY2(IPersist, IPersistFolder)
      //COM_INTERFACE_ENTRY(IPersistFolder)
      //COM_INTERFACE_ENTRY(IPersistFolder2)
      //COM_INTERFACE_ENTRY(IPersistFolder3)
      //COM_INTERFACE_ENTRY(IStorage)
      //COM_INTERFACE_ENTRY(IContextMenuCB)      
      //COM_INTERFACE_ENTRY(IItemNameLimits)
      //COM_INTERFACE_ENTRY(IObjectProvider)
      //COM_INTERFACE_ENTRY(IObjectWithSite)
      //COM_INTERFACE_ENTRY(IShellFolderViewCB)
      //COM_INTERFACE_ENTRY(IFolderViewSettings)
      //COM_INTERFACE_ENTRY(IExplorerPaneVisibility)
      //COM_INTERFACE_ENTRY(IThumbnailHandlerFactory)
   END_COM_MAP()

};

HRESULT WINAPI RegisterTest::UpdateRegistry(BOOL bRegister) throw()
{
	_ASSERTE (false);

	return S_OK;
}

OBJECT_ENTRY_AUTO(CLASS_GUID, RegisterTest)
